/*     */ package com.equipmentmanage.controller;
/*     */ 
/*     */ import com.equipmentmanage.model.Equipment;
import com.equipmentmanage.model.PageBean;
import com.equipmentmanage.model.Repair;
import com.equipmentmanage.model.User;
import com.equipmentmanage.service.EquipmentService;
import com.equipmentmanage.service.EquipmentTypeService;
import com.equipmentmanage.service.RepairService;
import com.equipmentmanage.util.PageUtil;
import com.equipmentmanage.util.ResponseUtil;
import com.equipmentmanage.util.StringUtil;

/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/equipment"})
/*     */ public class EquipmentController
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private EquipmentService equipmentService;
/*     */ 
/*     */   @Autowired
/*     */   private EquipmentTypeService equipmentTypeService;
/*     */ 
/*     */   @Autowired
/*     */   private RepairService repairService;
/*     */ 
/*     */   @RequestMapping({"/list"})
/*     */   public ModelAndView list(@RequestParam(value="page", required=false) String page, Equipment s_equipment, HttpServletRequest request)
/*     */   {
/*  49 */     ModelAndView mav = new ModelAndView();
/*  50 */     HttpSession session = request.getSession();
/*  51 */     if (StringUtil.isEmpty(page)) {
/*  52 */       page = "1";
/*  53 */       session.setAttribute("s_equipment", s_equipment);
/*     */     } else {
/*  55 */       s_equipment = (Equipment)session.getAttribute("s_equipment");
/*     */     }
/*  57 */     PageBean pageBean = new PageBean(Integer.parseInt(page), 3);
/*  58 */     List equipmentList = this.equipmentService.find(pageBean, s_equipment);
/*  59 */     int total = this.equipmentService.count(s_equipment);
/*  60 */     String pageCode = PageUtil.getPagation(request.getContextPath() + "/equipment/list.do", total, Integer.parseInt(page), 3);
/*  61 */     mav.addObject("pageCode", pageCode);
/*  62 */     mav.addObject("modeName", "设备管理");
/*  63 */     mav.addObject("equipmentList", equipmentList);
/*  64 */     mav.addObject("mainPage", "/jsp/equipment/list.jsp");
/*  65 */     mav.setViewName("main");
/*  66 */     return mav;
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/preSave"})
/*     */   public ModelAndView preSave(@RequestParam(value="id", required=false) String id) {
/*  71 */     ModelAndView mav = new ModelAndView();
/*  72 */     List equipmentTypeList = this.equipmentTypeService.find(null, null);
/*  73 */     mav.addObject("mainPage", "jsp/equipment/save.jsp");
/*  74 */     mav.addObject("modeName", "设备管理");
/*  75 */     mav.addObject("equipmentTypeList", equipmentTypeList);
/*  76 */     mav.setViewName("main");
/*  77 */     if (StringUtil.isNotEmpty(id)) {
/*  78 */       mav.addObject("actionName", "设备修改");
/*  79 */       Equipment equipment = this.equipmentService.loadById(Integer.parseInt(id));
/*  80 */       mav.addObject("equipment", equipment);
/*     */     } else {
/*  82 */       mav.addObject("actionName", "设备添加");
/*     */     }
/*  84 */     return mav;
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/save"})
/*     */   public String save(Equipment equipment) {
/*  89 */     if (equipment.getId() == null)
/*  90 */       this.equipmentService.add(equipment);
/*     */     else {
/*  92 */       this.equipmentService.update(equipment);
/*     */     }
/*  94 */     return "redirect:/equipment/list.do";
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/delete"})
/*     */   public void delete(@RequestParam("id") String id, HttpServletResponse response) throws Exception {
/*  99 */     JSONObject result = new JSONObject();
/* 100 */     this.equipmentService.delete(Integer.valueOf(id).intValue());
/* 101 */     result.put("success", Boolean.valueOf(true));
/* 102 */     ResponseUtil.write(result, response);
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/userList"})
/*     */   public ModelAndView userList(@RequestParam(value="page", required=false) String page, Equipment s_equipment, HttpServletRequest request) {
/* 107 */     ModelAndView mav = new ModelAndView();
/* 108 */     HttpSession session = request.getSession();
/* 109 */     if (StringUtil.isEmpty(page)) {
/* 110 */       page = "1";
/* 111 */       session.setAttribute("s_equipment", s_equipment);
/*     */     } else {
/* 113 */       s_equipment = (Equipment)session.getAttribute("s_equipment");
/*     */     }
/* 115 */     PageBean pageBean = new PageBean(Integer.parseInt(page), 3);
/* 116 */     List equipmentList = this.equipmentService.find(pageBean, s_equipment);
/* 117 */     int total = this.equipmentService.count(s_equipment);
/* 118 */     String pageCode = PageUtil.getPagation(request.getContextPath() + "/equipment/userList.do", total, Integer.parseInt(page), 3);
/* 119 */     mav.addObject("pageCode", pageCode);
/* 120 */     mav.addObject("modeName", "使用设备管理");
/* 121 */     mav.addObject("equipmentList", equipmentList);
/* 122 */     mav.addObject("mainPage", "jsp/equipment/userList.jsp");
/* 123 */     mav.setViewName("main");
/* 124 */     return mav;
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/repair"})
/*     */   public void repair(@RequestParam("id") String id, HttpSession session, HttpServletResponse response) throws Exception {
/* 129 */     JSONObject result = new JSONObject();
/* 130 */     String userMan = ((User)session.getAttribute("currentUser")).getUserName();
/* 131 */     this.equipmentService.addRepair(Integer.valueOf(id).intValue(), userMan);
/* 132 */     result.put("success", Boolean.valueOf(true));
/* 133 */     ResponseUtil.write(result, response);
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/finishRepair"})
/*     */   public void finishRepair(@RequestParam("id") String id, @RequestParam("success") boolean success, HttpSession session, HttpServletResponse response) throws Exception {
/* 138 */     JSONObject result = new JSONObject();
/* 139 */     String repairMan = ((User)session.getAttribute("currentUser")).getUserName();
/* 140 */     this.equipmentService.updateRepair(Integer.valueOf(id).intValue(), repairMan, success);
/* 141 */     result.put("success", Boolean.valueOf(true));
/* 142 */     ResponseUtil.write(result, response);
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/repairList"})
/*     */   public ModelAndView repairList(@RequestParam(value="page", required=false) String page, Repair s_repair, HttpServletRequest request)
/*     */   {
/* 148 */     ModelAndView mav = new ModelAndView();
/* 149 */     HttpSession session = request.getSession();
/* 150 */     if (StringUtil.isEmpty(page)) {
/* 151 */       page = "1";
/* 152 */       session.setAttribute("s_repair", s_repair);
/*     */     } else {
/* 154 */       s_repair = (Repair)session.getAttribute("s_repair");
/*     */     }
/* 156 */     s_repair.setFinishState(Integer.valueOf(1));
/* 157 */     PageBean pageBean = new PageBean(Integer.parseInt(page), 3);
/* 158 */     List repairList = this.repairService.find(pageBean, s_repair);
/* 159 */     int total = this.repairService.count(s_repair);
/* 160 */     String pageCode = PageUtil.getPagation(request.getContextPath() + "/equipment/repairList.do", total, Integer.parseInt(page), 3);
/* 161 */     mav.addObject("pageCode", pageCode);
/* 162 */     mav.addObject("modeName", "维修设备管理");
/* 163 */     mav.addObject("repairList", repairList);
/* 164 */     mav.addObject("mainPage", "jsp/equipment/repairList.jsp");
/* 165 */     mav.setViewName("main");
/* 166 */     return mav;
/*     */   }
/*     */ 
/*     */   @RequestMapping({"/repairHistory"})
/*     */   public ModelAndView repairHistory(@RequestParam(value="page", required=false) String page, Repair s_repair, HttpServletRequest request) {
/* 171 */     ModelAndView mav = new ModelAndView();
/* 172 */     HttpSession session = request.getSession();
/* 173 */     if (StringUtil.isEmpty(page)) {
/* 174 */       page = "1";
/* 175 */       session.setAttribute("s_repair", s_repair);
/*     */     } else {
/* 177 */       s_repair = (Repair)session.getAttribute("s_repair");
/*     */     }
/* 179 */     s_repair.setFinishState(Integer.valueOf(2));
/* 180 */     PageBean pageBean = new PageBean(Integer.parseInt(page), 3);
/* 181 */     List repairList = this.repairService.find(pageBean, s_repair);
/* 182 */     int total = this.repairService.count(s_repair);
/* 183 */     String pageCode = PageUtil.getPagation(request.getContextPath() + "/equipment/repairHistory.do", total, Integer.parseInt(page), 3);
/* 184 */     mav.addObject("pageCode", pageCode);
/* 185 */     mav.addObject("modeName", "历史记录管理");
/* 186 */     mav.addObject("repairList", repairList);
/* 187 */     mav.addObject("mainPage", "jsp/equipment/repairHistory.jsp");
/* 188 */     mav.setViewName("main");
/* 189 */     return mav;
/*     */   }
/*     */ }

/* Location:           C:\Users\arcgis\Desktop\新建文件夹\a0\[www.java1234.com]《SpringMvc设备管理系统》第零讲源码及文档\EquipmentSys\WEB-INF\classes\
 * Qualified Name:     com.java1234.controller.EquipmentController
 * JD-Core Version:    0.6.1
 */